//
//  LBCollectCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/11.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBCollectCell.h"

@interface LBCollectCell ()
@end
@implementation LBCollectCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifferCell = @"LBCollectCell";
    LBCollectCell *cell = [tableView dequeueReusableCellWithIdentifier:identifferCell];
    if (!cell) {
        cell = [[LBCollectCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifferCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}
- (void)setupUI{
    
    self.contentView.backgroundColor = [UIColor clearColor];
    UIView *backGroundView = [[UIView alloc]init];
    backGroundView.backgroundColor = [UIColor clearColor];
    self.selectedBackgroundView = backGroundView;
    
    self.icon = [[UIImageView alloc] init];
    self.icon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    self.icon.layer.cornerRadius = 5;
    self.icon.layer.masksToBounds = YES;
    
    [self.contentView addSubview:self.icon];
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15*kScaleFit);
        make.centerY.mas_equalTo(self.contentView);
        //        make.top.mas_equalTo(7*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(165*kScaleFit, 100*kScaleFit));
    }];
    
    
    self.freeIcon = [[UIImageView alloc] init];
    
    self.freeIcon.image = [UIImage imageNamed:@"wk_saomang_free"];
    
    [self.icon addSubview:self.freeIcon];
    [self.freeIcon makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-2*kScaleFit);
        make.right.mas_equalTo(-2*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(15*kScaleFit, 34*kScaleFit));
    }];
    
    self.freeIcon.hidden = YES;
    
    self.titleLab = [UILabel labelWithText:@"主题课程二级" andTextColor:rgb(51,51,51) andName:nil andFontSize:14*kScaleFit];
    [self.contentView addSubview:self.titleLab];
    [self.titleLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.top.mas_equalTo(self.icon.mas_top);
        make.right.mas_equalTo(-10*kScaleFit);
    }];
    
    self.detailLab = [UILabel labelWithText:@"激发孩子开口讲英语的兴趣，通过多元化的线上课堂，帮助孩子提升英语能力和综合素质。" andTextColor:rgb(51,51,51) andName:nil andFontSize:12*kScaleFit];
    [self.contentView addSubview:self.detailLab];
    self.detailLab.numberOfLines = 3;
    [self.detailLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.top.mas_equalTo(self.titleLab.mas_bottom).mas_equalTo(12*kScaleFit);
        make.right.mas_equalTo(-19*kScaleFit);
    }];
    
    self.priceLab = [UILabel labelWithText:@"￥699" andTextColor:rgb(233,38,18) andName:nil andFontSize:15*kScaleFit];
    [self.contentView addSubview:self.priceLab];
    self.detailLab.numberOfLines = 1;
    [self.detailLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10*kScaleFit);
        make.bottom.mas_equalTo(-6);
        //        make.right.mas_equalTo(-19*kScaleFit);
    }];
    
    self.contentView.userInteractionEnabled = YES;
    self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [self.deleteBtn  setImage:[UIImage imageNamed:@"wk_o"] forState:UIControlStateNormal];
//    [self.deleteBtn  setImage:[UIImage imageNamed:@"wk_Selection"] forState:UIControlStateSelected];
//    [self.deleteBtn addTarget:self action:@selector(clickDeleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.deleteBtn];
    //    self.deleteBtn.hidden = YES;
    [self.deleteBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(-30);
        make.centerY.mas_equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(25, 25));
    }];
    
}
- (void)setModel:(LBCourseCollectModel *)model{
    _model = model;
    if ([model.collectType isEqualToString:@"2"]) {
        self.titleLab.text = model.packageOutputDTO.packTitle;
        self.detailLab.text = model.packageOutputDTO.packName;
        NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,model.packageOutputDTO.imgUrl];
        NSURL *url = [NSURL URLWithString:urlString];
        [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    }else{
        self.titleLab.text = model.courseOutputDTO.courseTitle;
        self.detailLab.text = model.courseOutputDTO.courseName;
        NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,model.courseOutputDTO.courseImage];
        NSURL *url = [NSURL URLWithString:urlString];
        [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
    if (!self.editing)  return;
    [super setSelected:selected animated:animated];
    if (self.isEditing && self.isSelected) {
        self.contentView.backgroundColor     = [UIColor clearColor];
        //这里自定义了cell 就改变自定义控件的颜色
        self.textLabel.backgroundColor       = [UIColor clearColor];
        UIControl *control = [self.subviews lastObject];
        UIImageView * imgView = [[control subviews] objectAtIndex:0];
        imgView.image = [UIImage imageNamed:@"wk_Selection"];
    }
    
}
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    if (self.isEditing && self.isHighlighted ) {
        UIControl *control = [self.subviews lastObject];
        UIImageView * imgView = [[control subviews] objectAtIndex:0];
        imgView.image = [UIImage imageNamed:@"wk_Selection"];
    }
    return;
}



@end
